import { PlayerOptions } from './options'
import Video from './video'

import playerHtml from '../html/player.html'

export default class MicroPlayer {
	options: PlayerOptions
	container: HTMLElement
	video = undefined as unknown

	constructor(container: string | HTMLElement, options: PlayerOptions) {
		this.options = {
			autoPlay: false,
			loop: false,
			muted: true,
			preload: 'auto',
			controls: true,
			mutex: true,
			live: false,
			...options
		}

		if (typeof container === 'string') {
			const el = document.querySelector<HTMLElement>(container)
			if (!el) {
				throw new Error('无法找到容器元素')
			}
			this.container = el
		} else {
			this.container = container
		}

		this.init()
	}

	init() {
		this.container.innerHTML = playerHtml

		this.video = new Video(this.container, this.options)
	}

	static version = process.env.VERSION
}
